<template>
    <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :xl="6" :lg="7" :md="8" :sm="24">
                        <a-form-item label="企业名称">
                            <a-select placeholder="请输入企业名称" @change="getbyqiyeming"
                                v-model="queryParam.qiyemingcheng">
                                <a-select-option v-for="item in this.qiyeminglist" :value="item"
                                    :key="item">
                                    {{ item }}
                                </a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :xl="6" :lg="7" :md="8" :sm="24">
                        <span style="float: left;overflow: hidden;"
                            class="table-page-search-submitButtons">
                            <a-button type="primary" @click="searchQuery"
                                icon="search">查询</a-button>
                            <a-button type="primary" @click="searchReset" icon="reload"
                                style="margin-left: 8px">重置</a-button>
                            <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
                        </span>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
            <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('入库申请管理')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
            <!-- 高级查询区域 -->
            <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->

        </div>

        <!-- table区域-begin -->
        <div>
            <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

            <a-table ref="table" size="middle" bordered rowKey="id" class="j-table-force-nowrap"
                :scroll="{x:true}" :columns="columns" :dataSource="dataSource"
                :pagination="ipagination" :loading="loading"
                :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                @change="handleTableChange">

                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <template slot="imgSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                    <img v-else :src="getImgView(text)" height="25px" alt=""
                        style="max-width:80px;font-size: 12px;font-style: italic;" />
                </template>
                <template slot="fileSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                    <a-button v-else :ghost="true" type="primary" icon="download" size="small"
                        @click="downloadFile(text)">
                        下载
                    </a-button>

                </template>
                <!-- 入库状态 -->
                <template slot="rukuzhaungtai" slot-scope="text">
                    <a-tag v-if="text==0" color="blue">待审核</a-tag>
                    <a-tag v-if="text==1" color="green">审核通过</a-tag>
                    <a-tag v-if="text==2" color="green">核验完毕</a-tag>
                    <a-tag v-if="text==3" color="red">驳回</a-tag>
                    <a-tag v-if="text==4" color="yellow">入库完成</a-tag>
                </template>

                <span slot="action" slot-scope="text, record">
                    <a @click="handleEdit(record)">编辑</a>

                    <a-divider type="vertical" />
                    <a-dropdown>
                        <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                        <a-menu slot="overlay">
                            <a-menu-item>
                                <a @click="handleDetail(record)">详情</a>
                            </a-menu-item>
                            <a-menu-item v-if="record.rukuzhaungtai==0">
                                <a @click="shenhetongguo(record)">审核通过</a>
                            </a-menu-item>
                            <a-menu-item v-if="record.rukuzhaungtai==0">
                                <a @click="shenhebohui(record)">审核驳回</a>
                            </a-menu-item>
                            <a-menu-item>
                                <a-popconfirm title="确定删除吗?"
                                    @confirm="() => handleDelete(record.id)">
                                    <a>删除</a>
                                </a-popconfirm>
                            </a-menu-item>
                        </a-menu>
                    </a-dropdown>
                </span>

            </a-table>
        </div>

        <yzd-shenqingguanli-modal ref="modalForm" @ok="modalFormOk" />

    </a-card>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import YzdShenqingguanliModal from './modules/YzdShenqingguanliModal'
import '@/assets/less/TableExpand.less'
import { getAction, postAction } from '../../api/manage'

export default {
    name: "YzdShenqingguanliList",
    mixins: [JeecgListMixin],
    components: {
        YzdShenqingguanliModal
    },
    data() {
        return {
            xianshi: true,

            description: '入库申请管理管理页面',
            // 表头
            columns: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: "center",
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1;
                    }
                },
                {
                    title: '企业名称',
                    align: "center",
                    dataIndex: 'gongsimingcheng',
                },
                {
                    title: '公安文件',
                    align: "center",
                    dataIndex: 'gonganwenjian',
                    scopedSlots: { customRender: 'fileSlot' }
                },
                // {
                //   title:'入库状态',
                //   align:"center",
                //   dataIndex: 'rukuzhaungtai',
                //   scopedSlots: {customRender: 'rukuzhaungtai'}
                // },
                // {
                //   title:'货物类别',
                //   align:"center",
                //   dataIndex: 'huaxuepinleibie'
                // },
                {
                    title: '货物名称',
                    align: "center",
                    dataIndex: 'huaxuepinmingcheng'
                },
                // {
                //   title:'CAS号',
                //   align:"center",
                //   dataIndex: 'cashao'
                // },
                {
                    title: '入库时间',
                    align: "center",
                    sorter: true,
                    dataIndex: 'rukushijan',
                    customRender: function (text) {
                        return !text ? "" : (text.length > 10 ? text.substr(0, 16) : text)
                    }
                },
                {
                    title: '入库人姓名',
                    align: "center",
                    dataIndex: 'rukurenxingming'
                },
                // {
                //   title:'入库人部门',
                //   align:"center",
                //   dataIndex: 'rukurenbumen'
                // },
                {
                    title: '净含量(克)',
                    align: "center",
                    dataIndex: 'rukuliang'
                },
                // {
                //   title:'回皮重量(克)',
                //   align:"center",
                //   dataIndex: 'huipizhongliang'
                // },
                {
                    title: '入库瓶数',
                    align: "center",
                    dataIndex: 'rukupingshu'
                },
                // {
                //   title:'仓库名称',
                //   align:"center",
                //   dataIndex: 'cangkumingcheng'
                // },
                {
                    title: '购买时间',
                    align: "center",
                    dataIndex: 'goumaishijian',
                    customRender: function (text) {
                        return !text ? "" : (text.length > 10 ? text.substr(0, 16) : text)
                    }
                },
                {
                    title: '购买厂家',
                    align: "center",
                    dataIndex: 'goumaichangjia'
                },
                {
                    title: '司机姓名',
                    align: "center",
                    dataIndex: 'sijixingming'
                },
                {
                    title: '车牌号',
                    align: "center",
                    dataIndex: 'chepaihao'
                },
                // {
                //   title:'进入仓库拍照',
                //   align:"center",
                //   dataIndex: 'jinrucangkupaizhao',
                //   scopedSlots: {customRender: 'imgSlot'}
                // },
                // {
                //   title:'打开柜门拍照',
                //   align:"center",
                //   dataIndex: 'dakaiguimenpaizhao',
                //   scopedSlots: {customRender: 'imgSlot'}
                // },
                // {
                //   title:'驳回原因',
                //   align:"center",
                //   dataIndex: 'bohuiyuanyin'
                // },
                // {
                //   title:'仓库位置',
                //   align:"center",
                //   dataIndex: 'cangkuweizhi'
                // },
                // {
                //   title: '操作',
                //   dataIndex: 'action',
                //   align:"center",
                //   fixed:"right",
                //   width:147,
                //   scopedSlots: { customRender: 'action' },
                // }
            ],
            url: {
                getqiyeminglist: "/yzd_rukuguanli/yzdShenqingguanli/getQiyeming",
                getbyqiyeming: "/yzd_rukuguanli/yzdShenqingguanli/getByQiyemingcheng",
                // getqiyeming: "/yzd_rukuguanli/yzdShenqingguanli/getByQiyemingcheng",
                shenhe: "/yzd_rukuguanli/yzdShenqingguanli/shenhe",
                list: "/yzd_rukuguanli/yzdShenqingguanli/list",
                delete: "/yzd_rukuguanli/yzdShenqingguanli/delete",
                deleteBatch: "/yzd_rukuguanli/yzdShenqingguanli/deleteBatch",
                exportXlsUrl: "/yzd_rukuguanli/yzdShenqingguanli/exportXls",
                importExcelUrl: "yzd_rukuguanli/yzdShenqingguanli/importExcel",

            },
            dictOptions: {},
            superFieldList: [],
            dataSource: [],
            qiyeminglist: [],
        }
    },
    created() {
        this.getSuperFieldList();
        this.getqiyeming();
        this.getbyqiyeming();
    },
    computed: {
        importExcelUrl: function () {
            return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
        }
    },
    methods: {
        getqiyeming() {
            getAction(this.url.getqiyeminglist).then(res => {
                this.qiyeminglist.push("全部")
                console.log(res);
                res.result.forEach(element => {
                    this.qiyeminglist.push(element.gongsimingcheng)
                })
            })
        },

        getbyqiyeming(arr) {
            console.log(arr);
            if (arr == "全部" || arr == undefined) {
                arr = ''
            }
            var re = {
                gongsimingcheng: arr
            }
            getAction(this.url.getbyqiyeming, re).then(res => {
                console.log(res);
                this.dataSource = res.result
            })
        },


        shenhetongguo(arr) {
            this.xianshi = false,
                arr.rukuzhaungtai = 1
            console.log(arr);
            postAction(this.url.shenhe, arr).then(res => {
                console.log(res);
            })
        },
        shenhebohui(arr) {
            this.xianshi = false,
                arr.rukuzhaungtai = 2
            console.log(arr);
        },

        initDictConfig() {
        },
        getSuperFieldList() {
            let fieldList = [];
            fieldList.push({ type: 'string', value: 'gonganwenjian', text: '公安文件', dictCode: '' })
            fieldList.push({ type: 'string', value: 'rukuzhaungtai', text: '入库状态', dictCode: '' })
            fieldList.push({ type: 'string', value: 'huaxuepinleibie', text: '货物类别', dictCode: '' })
            fieldList.push({ type: 'string', value: 'huaxuepinmingcheng', text: '货物名称', dictCode: '' })
            fieldList.push({ type: 'string', value: 'cashao', text: 'CAS号', dictCode: '' })
            fieldList.push({ type: 'date', value: 'rukushijan', text: '入库时间' })
            fieldList.push({ type: 'string', value: 'rukurenxingming', text: '入库人姓名', dictCode: '' })
            fieldList.push({ type: 'string', value: 'rukurenbumen', text: '入库人部门', dictCode: '' })
            fieldList.push({ type: 'BigDecimal', value: 'rukuliang', text: '入库量(克)', dictCode: '' })
            fieldList.push({ type: 'BigDecimal', value: 'huipizhongliang', text: '回皮重量(克)', dictCode: '' })
            fieldList.push({ type: 'int', value: 'rukupingshu', text: '入库瓶数', dictCode: '' })
            fieldList.push({ type: 'string', value: 'cangkumingcheng', text: '仓库名称', dictCode: '' })
            fieldList.push({ type: 'date', value: 'goumaishijian', text: '购买时间' })
            fieldList.push({ type: 'string', value: 'goumaichangjia', text: '购买厂家', dictCode: '' })
            fieldList.push({ type: 'string', value: 'sijixingming', text: '司机姓名', dictCode: '' })
            fieldList.push({ type: 'string', value: 'chepaihao', text: '车牌号', dictCode: '' })
            fieldList.push({ type: 'string', value: 'jinrucangkupaizhao', text: '进入仓库拍照', dictCode: '' })
            fieldList.push({ type: 'string', value: 'dakaiguimenpaizhao', text: '打开柜门拍照', dictCode: '' })
            fieldList.push({ type: 'string', value: 'bohuiyuanyin', text: '驳回原因', dictCode: '' })
            fieldList.push({ type: 'string', value: 'cangkuweizhi', text: '仓库位置', dictCode: '' })
            this.superFieldList = fieldList
        }
    }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>

